package com.fjwt.gz.proxy.ctrl.award.awardemployee;


import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fjwt.gz.core.model.ApiRes;
import com.fjwt.gz.db.dto.AwardEmployeeDTO;
import com.fjwt.gz.db.vo.AwardEmployeeVO;
import com.fjwt.gz.proxy.ctrl.CommonCtrl;
import com.fjwt.gz.service.impl.AwardEmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/***
 * 奖品员工中间表 Controller
 *
 */
@RestController
@Slf4j
@RequestMapping("/api/award/employee")
public class AwardEmployeeController extends CommonCtrl {

    @Autowired
    private AwardEmployeeService awardEmployeeService;


    /**
     * 获取可派发人员名单
     *
     * @return
     */
    @PostMapping("/getAllocationUserList")
    public ApiRes getAllocationUserList() {
        AwardEmployeeDTO employeeDTO = getObject(AwardEmployeeDTO.class);
        log.info("机构端获取可派发人员名单接口:/api/award/employee/getAllocationUserList,请求参数：{}", JSONUtil.toJsonStr(employeeDTO));
        IPage<AwardEmployeeVO> page = awardEmployeeService.getEmployeeDistributeList(getIPage(), employeeDTO);
        log.info("机构端获取可派发人员名单接口:/api/award/employee/getAllocationUserList,返回结果：{}", JSONUtil.toJsonStr(page));
        return ApiRes.page(page);
    }

    /**
     * 新增单个可派发人员
     *
     * @return
     */
    @PostMapping("/addAllocationUser")
    public ApiRes addAllocationUser() {
        AwardEmployeeDTO employeeDTO = getObject(AwardEmployeeDTO.class);
        log.info("机构端新增单个可派发人员接口:/api/award/employee/addAllocationUser,请求参数：{}", JSONUtil.toJsonStr(employeeDTO));
        awardEmployeeService.addOneEmployeeDistribute(employeeDTO);
        return ApiRes.ok();
    }

    /**
     * 上传可派发人员名单 批量导入
     *
     * @return
     */
    @PostMapping("/addAllocationUserFile")
    public ApiRes addAllocationUserFile() {
        AwardEmployeeDTO employeeDTO = getObject(AwardEmployeeDTO.class);
        log.info("机构端上传可派发人员名单 批量导入接口:/api/award/employee/addAllocationUserFile,请求参数：{}", JSONUtil.toJsonStr(employeeDTO));
        awardEmployeeService.importBatchEmployeeDistributeByFile(employeeDTO);
        return ApiRes.ok();
    }

    /**
     * 更新可派发人员的渠道码是否可见
     * @return
     */
    @PostMapping("/updateEmpChannelDisplay")
    public ApiRes updateEmpChannelDisplay() {
        AwardEmployeeDTO employeeDTO = getObject(AwardEmployeeDTO.class);
        log.info("机构端更新可派发人员的渠道码是否可见接口:/api/award/employee/updateEmpChannelDisplay,请求参数：{}", JSONUtil.toJsonStr(employeeDTO));
        awardEmployeeService.updateEmpChannelDisplay(employeeDTO);
        return ApiRes.ok();
    }


    /**
     * 删除可派发人员名单
     *
     * @return
     */
    @PostMapping("/deleteAllocationUserFile")
    public ApiRes deleteAllocationUserFile() {
        Long awardEmployeeId = getValLong("awardEmployeeId");
        log.info("机构端删除可派发人员名单接口:/api/award/employee/deleteAllocationUserFile,请求参数：{}", awardEmployeeId);
        if (null == awardEmployeeId) {
            return ApiRes.customFail("请求参数缺失！");
        }
        awardEmployeeService.removeById(awardEmployeeId);
        return ApiRes.ok();
    }

    /**
     * 删除所有的可派发人员名单
     *
     * @return
     */
    @PostMapping("/deleteAllAllocationUser")
    public ApiRes deleteAllAllocationUser() {
        Long awardId = getValLong("awardId");
        Integer awardType = getValInteger("awardType");
        log.info("C端删除所有的可派发人员名单接口:/api/award/employee/deleteAllAllocationUser,请求参数：awardId:{}, awardType{}", awardId, awardType);
        awardEmployeeService.removeAllAllocationUserByAwardId(awardId, awardType);
        return ApiRes.ok();
    }


}
